package dmir.wikipedia;


import java.util.List;
import java.util.Set;

import dmir.wikipedia.cleaners.AbstractWikiPageCleaner;
import dmir.wikipedia.cleaners.EnglishWikiPageCleaner;
import dmir.wikipedia.cleaners.PortugueseWikiPageCleaner;
import dmir.wikipedia.cleaners.SpanishWikiPageCleaner;

public class WikiPage {

    private String title;
    private String wikiText;
    private StringBuilder editableWikiText;
    private AbstractWikiPageCleaner cleaner;
    
    public WikiPage(StringBuilder title, StringBuilder rawText, String lang) 
    {
        this.title = encodeWikistyle(title.toString());
        this.editableWikiText = rawText;
        
        if (lang.equalsIgnoreCase("Spanish")) {
        	this.cleaner = new SpanishWikiPageCleaner(this.title, rawText);
        } 
        else if (lang.equalsIgnoreCase("Portuguese")) {
        	this.cleaner = new PortugueseWikiPageCleaner(this.title, rawText);
        } 
        else {
        	this.cleaner = new EnglishWikiPageCleaner(this.title, rawText);
        }
    }
    
    public String getTitle() {
        return title;
    }

    public String getWikiText() {
        if (wikiText == null) wikiText = editableWikiText.toString(); 
        return wikiText;
    }

    public String getPlainText() {
        return cleaner.getCleanText();
    }
    
    public List<WikiLink> getLinks() {
        return cleaner.getLinks();
    }
    
    public boolean isRedirect() {
        return cleaner.isRedirect();
    }
    
    public boolean isDisambiguation() {
        return cleaner.isDisambiguation();
    }
    
    public Set<String> getCategories() {
        return cleaner.getCategories();
    }
    
    public String getInfobox() {
        return cleaner.getInfobox();
    }
    
    public Double[] getLatLng() {
        return cleaner.getLatLng();
    }
    
    public Long getPopulation() {
    	return cleaner.getPopulation();
    }
    
    public Float getArea()
    {
    	return cleaner.getArea();
    }
    
	public static String encodeWikistyle(String str)
	{
		if ( !Character.isUpperCase(str.charAt(0)) ) {
			char[] ca = str.toCharArray();
			ca[0] = Character.toUpperCase( str.charAt(0) );
			str = new String(ca);
		}
		
		return str.replace(' ', '_');
	}

	public boolean ignore() 
	{
		return cleaner.ignore();
	}
}
